package com.zhiwei.save;

import org.bson.Document;

import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;

public class LinkMongo {
    
    static MongoClient mongoClient = null;
    public static MongoCollection<Document> getMongoCollection(String dataBase,String dbtable) {
        try {
            mongoClient = new MongoClient("192.168.0.244");
            MongoDatabase mongoDatabase = mongoClient.getDatabase(dataBase);
            MongoCollection<Document> mongoCollection = mongoDatabase.getCollection(dbtable);
            return mongoCollection;
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    
    public static void closeMongoCollection() {
        if(mongoClient != null){
            mongoClient.close();
        }
    }
    
}
